package com.micro.ai.template.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.micro.ai.template.entity.ExecutionLog;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 执行日志Mapper
 *
 * @author micro-ai
 * @since 0.0.1
 */
@Mapper
public interface ExecutionLogMapper extends BaseMapper<ExecutionLog> {

    /**
     * 根据Agent ID查询执行日志
     */
    @Select("SELECT * FROM execution_logs WHERE agent_id = #{agentId} ORDER BY created_at DESC LIMIT #{limit}")
    List<ExecutionLog> selectByAgentId(@Param("agentId") String agentId, @Param("limit") Integer limit);

    /**
     * 根据时间范围查询执行日志
     */
    @Select("SELECT * FROM execution_logs WHERE agent_id = #{agentId} " +
            "AND created_at >= #{startTime} AND created_at <= #{endTime} ORDER BY created_at DESC")
    List<ExecutionLog> selectByTimeRange(
            @Param("agentId") String agentId,
            @Param("startTime") LocalDateTime startTime,
            @Param("endTime") LocalDateTime endTime
    );

    /**
     * 统计执行日志
     */
    @Select("SELECT COUNT(*) FROM execution_logs WHERE agent_id = #{agentId} AND status = #{status}")
    Integer countByStatus(@Param("agentId") String agentId, @Param("status") String status);
}

